//
//  QuartzFunViewController.m
//  iPhoneDev01
//
//  Created by smu on 11-7-14.
//  Copyright 2011年 duk. All rights reserved.
//

#import "QuartzFunViewController.h"
#import "QuartzFunView.h"
#import "Constants.h"

@implementation QuartzFunViewController
@synthesize colorControl;

//确定已选择的分段，并根据选择内容创建一个新颜色
- (IBAction)changeColor:(id)sender
{
    UISegmentedControl *control = sender;
    NSInteger index = [control selectedSegmentIndex];
    //将view转换为QuartzFunView
    QuartzFunView *quartzView = (QuartzFunView *)self.view;
    switch (index) {
        case kRedColorTab:
            quartzView.currentColor = [UIColor redColor];
            quartzView.useRandomColor = NO;
            break;
        case kBlueColorTab:
            quartzView.currentColor = [UIColor blueColor];
            quartzView.useRandomColor = NO;
            break;
        case kYellowColorTab:
            quartzView.currentColor = [UIColor yellowColor];
            quartzView.useRandomColor = NO;
            break;
        case kGreenColorTab:
            quartzView.currentColor = [UIColor greenColor];
            quartzView.useRandomColor = NO;
        case kRandomColorTab:
            quartzView.useRandomColor = YES;
            break;
        default:
            break;
    }
}

- (IBAction)changeShape:(id)sender
{
    UISegmentedControl *control = sender;
    //形状设置为与当前所选择的分段相同
    [(QuartzFunView *)self.view setShapeType:[control selectedSegmentIndex]];
    //是否选择了Image分段来隐藏colorControll和取消隐藏colorControl
    if ([control selectedSegmentIndex] == kImageShape) {
        colorControl.hidden = YES;
    } else {
        colorControl.hidden = NO;
    }
}



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [colorControl release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    self.colorControl = nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
